/**
 * Created by wangshuo on 2016/3/1.
 */
//根据所在区查询医疗机构
function getHospitalsByCounty(value,id) {
    url=joinUrl('/common/getExamHospitalsByCounty');
    $.ajax({
        url: url,
        data: {value: value},
        type: 'post',
        dataType: 'json',
        success: function (data) {
            if (data.code == 0) {
                var html = "";
                var arr = data.data;
                $("#"+id).empty();
                for (var i = 0; i < arr.length; i++) {
                    html += '<option value="' + arr[i].hospitalId + '">' + arr[i].hospitalName + '</option>';
                }
                $('#'+id).html(html);
            }
        },
        error: function (e) {
            $("#"+id).empty();
            var emptyHtml = "<option value=''>全部</option>";
            $('#'+id).html(emptyHtml);
            layer.alert("获取检查医疗机构失败");
        }
    });
}
//根据所在区和医疗机构查询学校
function getSchoolsByCounty(county,hospital,id) {
    url=joinUrl('/common/getSchoolsByCounty');
    $.ajax({
        url: url,
        data: {county: county,
               hospital:hospital},
        type: 'post',
        dataType: 'json',
        success: function (data) {
            if (data.code == 0) {
                var html = "";
                var arr = data.data;
                $("#"+id).empty();
                for (var i = 0; i < arr.length; i++) {
                    html += '<option value="' + arr[i].schoolId + '">' + arr[i].schoolName + '</option>';
                }
                $('#'+id).html(html);
            }
        },
        error: function (e) {
            $("#"+id).empty();
            var emptyHtml = "<option value=''>全部</option>";
            $('#'+id).html(emptyHtml);
            layer.alert("获取学校列表失败");
        }
    });
}
//根据生日计算年龄
function getAge(birthday){
    if(birthday==""){
        return "";
    }else{
        birthday= birthday.replace(/-/g,"/");
        var date=new Date(birthday);
        var today=new Date();
        var t=today.getTime()-date.getTime();
        return Math.floor(t / (24 * 60 * 60 * 1000 * 365));
    }
}

//根据出生日期和截止日期计算年龄
function getAgeByDate(birthday,nowdate){
    debugger;
    if(birthday==""){
        return "";
    }else{
        birthday= birthday.replace(/-/g,"/");
        var date=new Date(birthday);
        var today=new Date(nowdate);
        var t=today.getTime()-date.getTime();
        return Math.floor(t / (24 * 60 * 60 * 1000 * 365));
    }
}
